﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectStorageLib.Project;
using ProjectStorageDB;

public partial class Commercial_AllProjects : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lMess.Visible = false;
        lMess.InnerText = "";
    }

    public List<ProjectStorageLib.Project.ProjectManager> GetFiltaredData()
    {
        try
        {
            if (pGrid.IncludedRows != null && pGrid.IncludedRows.Count > 0)
            {
                return GetData().Where(data => pGrid.IncludedRows.Contains(data.Project.ProjectID)).ToList();

            }   
        }
        catch (Exception err)
        {
            lMess.Visible = true;
            lMess.InnerText = err.ToString();
        }
        return null;
    }

    public List<ProjectStorageLib.Project.ProjectManager> GetData()
    {
        //locals
        List<decimal> projectsId = null;
        List<ProjectStorageLib.Project.ProjectManager> list = null;
        ProjectStorageLib.Project.ProjectManagerPocessor proc = null;

        try
        {
            //create processor
            proc = new ProjectManagerPocessor();

            //Get ID of all projects
            projectsId = proc.GetAllProjectsId();

            //If thre projects add them
            if (projectsId != null)
            {
                list = new List<ProjectManager>();

                foreach (decimal id in projectsId)
                {
                    list.Add(new ProjectManager(id));
                }
            }
        }
        catch (Exception err)
        {
            lMess.Visible = true;
            lMess.InnerText = err.ToString();
        }
        finally
        {
            if (proc != null)
                proc.Dispose();
        }

        return list;

    }
}